package procilege.impl.formatter;

import java.util.Iterator;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.lang.PrivExprComposition;
import procilege.lang.PrivExprElement;

@PlaceTypeMetadata(type = PrivExprComposition.class)
public class PrivExprCompositionFormatter implements
		PlaceType<ExprFormatTraveller> {

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();
		sb.append("(");
		Iterator<PrivExprElement> it = ((PrivExprComposition) place).iterator();
		if (it.hasNext()) {
			PrivExprElement t = it.next();
			tr.setout(t);

			while (it.hasNext()) {

				sb.append("+");
				t = it.next();
				tr.setout(t);
			}
		}
		sb.append(")");
	}
}